home *** CD-ROM | disk | FTP | other *** search
- /*
- * menu.c - menu handling.
- */
-
- #include <quickdraw.h>
- #include <memory.h>
- #include <window.h>
- #include <menu.h>
- #include <desk.h>
- #include <toolutil.h>
- #include <packages.h>
-
- #include "critic.h"
-
- #define DATA
- #include "items.h"
- #undef DATA
-
- #define DLGABOUT 256 /* ResId of our "About..." dialog */
-
- /*
- * menu_init() - Initialize the menus and desk accessories (drivers).
- */
-
- menu_init()
- {
- int i; /* current menu number */
- short theitem; /* the current item in a menu */
- char name[64]; /* the name of a Font */
-
- /*
- * Get each of our menus from the resources,
- * add all desk accessories to the Apple menu,
- * Then install the menus in the menu bar.
- */
-
- for (i = 1; i <= LASTMENU; i++) {
- mymenus[i] = GetMenu(i);
- }
- AddResMenu(mymenus[APPLEMENU], 'DRVR');
-
- for (i = 1; i <= LASTMENU; i++) {
- InsertMenu(mymenus[i], 0); /* put menus at end */
- }
- DrawMenuBar();
- }
-
- /*
- * docommand() - handle a command given through a menu selection.
- *
- * If the command is Quit, we return true, else false.
- * Since the menu was highlighted by MenuSelect, we must finish
- * by unhighlighting it to indicate we're done.
- */
-
- int /* "the command was 'quit' */
- docommand(mresult)
- long mresult; /* the command to execute (a menu item) */
- {
- GrafPtr saveport;
- int themenu; /* the chosen menu */
- int theitem; /* the chosen item */
- WindowPtr thewindow; /* the active window */
- char name[64]; /* the name of a DA */
- int returns; /* result to return */
-
- returns = 0; /* assume Quit not selected */
- themenu = HiWord(mresult); /* get the menu selected */
- theitem = LoWord(mresult); /* ... and the item of that menu */
- thewindow = FrontWindow();
- switch (themenu) {
- case 0: /* no selection -- do nothing */
- break;
-
- case APPLEMENU:
- switch (theitem) {
- case AP_ABOUT: /* Tell about the program */
- saydialog(DLGABOUT);
- break;
- default: /* Run the selected Desk Accessory */
- GetPort(&saveport);
- GetItem(mymenus[APPLEMENU], theitem, name);
- (void) OpenDeskAcc(name);
- SetPort(saveport);
- break;
- }
- break;
-
- case FILEMENU:
- switch (theitem) {
- case IQUIT: /* Quit the program */
- returns = 1;
- break;
- }
- break;
-
- case EDITMENU:
- switch (theitem) {
- case UNDOEDIT:
- case CUTEDIT:
- case COPYEDIT:
- case PASTEEDIT:
- case CLEAREDIT:
- if (thewindow == windoc) { /* our window */
- /* if we could do edit operations, we'd do them here */
- } else { /* a DA's window */
- SystemEdit(theitem - 1);
- }
- break;
- }
- break;
-
- case VOICEMENU:
- switch (theitem) {
- case VO_SETUP:
- setupvoice();
- break;
- }
- break;
- }
- HiliteMenu(0); /* we're done -- turn off the highlighting */
- return(returns);
- }
-
- /*
- * markmenus() - take care of checking and dimming all items in all menus.
- * This routine should be the only one that fiddles with menu item
- * checking and dimming.
- */
-
- markmenus(whichwindow)
- WindowPtr whichwindow; /* the active window */
- {
- MenuHandle themenu;
- char txt[64]; /* (pascal) menu item text */
-
- /* Apple menu is O.K. */
- /* File menu is O.K. */
-
- /*
- * Edit menu: dim it if our window is active.
- * Otherwise, light it.
- */
-
- themenu = mymenus[EDITMENU];
- if (whichwindow == windoc) {
- DisableItem(themenu, UNDOEDIT);
- DisableItem(themenu, CUTEDIT);
- DisableItem(themenu, COPYEDIT);
- DisableItem(themenu, PASTEEDIT);
- DisableItem(themenu, CLEAREDIT);
- } else {
- EnableItem(themenu, UNDOEDIT);
- EnableItem(themenu, CUTEDIT);
- EnableItem(themenu, COPYEDIT);
- EnableItem(themenu, PASTEEDIT);
- EnableItem(themenu, CLEAREDIT);
- }
-
- /* Voice menu is O.K. */
- }
-